import React, { Component, PropTypes } from 'react';
import { Router, Route, Redirect, IndexRoute } from 'react-router';
import { Provider } from 'react-redux';
import { store } from './store';

import * as View from './views/Index';

class Root extends Component {
  static propTypes = {
    history: PropTypes.object.isRequired
  }

  handleRouteUpdate(){
    let { onRouteUpdate } = this.props;
    if (onRouteUpdate) {
        onRouteUpdate();
    }
  }

  render() {
    const { history } = this.props;
    return (
        <Provider store={store}>
          {() =>
              <Router location={history} onUpdate = {this.handleRouteUpdate.bind(this)}>
                <Route path="/" component={View.Auth}/>
                <Route path='/Account' name="Account" component={View.Account}/>
                <Route path='/Register' name="Register" component={View.Register}/>
                <Route path='/WxUpgrade' name="WxUpgrade" component={View.WxUpgrade}/>
                <Route path='/WxUpgrade2' name="WxUpgrade2" component={View.WxUpgrade2}/>
                <Route path='/FindPwd' name="FindPwd" component={View.FindPwd}/>
                <Route path='/FindPwd2' name="FindPwd2" component={View.FindPwd2}/>
                <Route path='/FindPwd3' name="FindPwd2" component={View.FindPwd3}/>
                <Route path='/Login' name="Login" component={View.Login}/>

                <Route path='/Product' name="Product" component={View.Product}/>
                <Route path="/ProductDetail" name="ProductDetail" component={View.ProductDetail} />

                <Route path='/Pocket' name="Pocket" component={View.Pocket}/>
                <Route path='/Discover' name="Discover" component={View.Discover}/>
                <Route path='/User' name="User" component={View.User}/>

                <Route path='/Message' name="Message" component={View.Message}/>
                <Route path='/MessageDetail' name="MessageDetail" component={View.MessageDetail}/>

                <Route path='/Recharge' name="Recharge" component={View.Recharge}/>
                <Route path='/Record' name="Record" component={View.Record}/>
                <Route path='/About' name="About" component={View.About}/>
                <Route path='/Document' name="Document" component={View.Document}/>
                <Route path='/Setting' name="Setting" component={View.Setting}/>
                <Route path='/More' name="More" component={View.More}/>
                <Route path='/Bind' name="Bind" component={View.Bind}/>

                <Route path='/Recommend' name="Recommend" component={View.Recommend}/>
                <Route path='/Protocol' name="Protocol" component={View.Protocol}/>
                <Route path='/ProtocolLong' name="ProtocolLong" component={View.ProtocolLong}/>
                <Route path='/ProtocolRecharge' name="ProtocolRecharge" component={View.ProtocolRecharge}/>
                <Route path='/RuleLong' name="Protocol" component={View.RuleLong}/>
              </Router>
          }
        </Provider>
    );
  }
}

export default Root;
